package com.alan.mr;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by Alan on 2017/9/29.
 */
public class WcReducer extends Reducer<Text,IntWritable,Text,IntWritable> {

    /**
     *
     * @param key
     * @param iterable
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(Text key, Iterable<IntWritable> iterable, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable i:iterable) {
            sum = sum + i.get();
        }
        context.write(key,new IntWritable(sum));
    }
}
